{extend name="layout/base" /}
<!-- 标题 -->
{block name="title"}{$column['column_name']}{/block}
<!-- CSS -->
{block name="css"}{/block}

<!-- 具体内容 -->
{block name="content"}
<h2 class="header-dividing">{$column['column_name']} <small>{$column['column_enname']}</small></h2>
<div class="navbar navbar-default navbar-content">
    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
            <li><a data-toggle="modal" data-target="#modal-create" data-action="{:url('@admin/wsphoto/save')}"> <i class="icon icon-plus"></i> 添加内容</a></li>
            {if($column['column_cate'])}
            <li><a href="{:url('@admin/wscate', $urlparam)}"> <i class="icon icon-branch"></i> 内容分类</a></li>
            {/if}
            <li><a href="{:url('@admin/wscolumn', $urlparam)}"> <i class="icon icon-lightbulb"></i> 栏目设置</a></li>
        </ul>
        <!-- 导航中的表单 -->
        <form class="navbar-form navbar-left" role="search" method="get" action="{:url('@admin/wsphoto')}">
            <input type="hidden" name="siteid" value="{$siteid}">
            <input type="hidden" name="columnid" value="{$columnid}">
            {if($column['column_cate'])}
            <select class="form-control" name="cateid">
                <option value="">请选择分类</option>
                {volist name="wscate" id="vo"}
                <option value="{$vo['wscate_id']}" {$vo['wscate_id']!=$cateid?:'selected'}>{:dp_prefix($vo['wscate_path'])}{$vo['wscate_name']}</option>
                {/volist}
            </select>
            {/if}
            <input type="text" class="form-control" name="keywords" placeholder="搜索" value="{$keywords}">
            <button type="submit" class="btn btn-default">搜索</button>
            <button type="button" class="btn" data-remote="{:url('@admin/help/main')}" data-show-header="false" data-toggle="modal">帮助</button>
        </form>
    </div>
</div>

<div class="panel">
    <table class="table datatable table-fixed" data-checkable="true" data-check-by-click-row="false">
        <thead>
            <tr>
                <th data-width="80" width="80" class="text-center">ID</th>
                <th data-width="100" width="100" class="text-center">图片</th>
                <th>标题</th>
                <th>时间</th>
                <th data-width="100" width="100" class="text-center">排序</th>
                <th data-width="80" width="80" class="text-center">修改</th>
                <th data-width="80" width="80" class="text-center">复制</th>
                <th data-width="80" width="80" class="text-center">删除</th>
            </tr>
        </thead>
        <tbody>
            {volist name="list" id="vo"}
            <tr data-id="{$vo['wsarticle_id']}">
                <td class="text-center">{$vo['wsarticle_id']}</td>
                <td>
                    <a href="{:getimg($vo['wsarticle_image'])}" class="lightbox-toggle" target="banner">
                        <img class="img-rounded img-bg img-3x2" data-imgsrc="{:getimg($vo['wsarticle_image'])}">
                    </a>
                </td>
                <td>
                    <p class="mb5"><label class="label label-primary">标题</label> {$vo['wsarticle_title']}</p>
                    {if($column['column_cate'])}
                    <p class="mb5"><label class="label label-primary">分类</label> {:show_cate2($vo['wsarticle_cateid'], $wscate)}</p>
                    {/if}
                    <p class="mb0 text-muted" title="{$vo['wsarticle_desc']}"><label class="label">描述</label> {:sub_str($vo['wsarticle_desc'], 50)}</p>
                </td>
                <td class="text-muted">{$vo['wsarticle_create_time']}</td>
                <td class="text-center"><input type="text" class="form-control text-center sort" data-url="{:url('@admin/wsarticle/sort')}" data-old-sort="{$vo['wsarticle_sort']}" data-id="{$vo['wsarticle_id']}" value="{$vo['wsarticle_sort']}"></td>
                <td class="text-center"><a data-toggle="modal" data-target="#modal-create" data-url="{:url('@admin/wsphoto/edit', 'id='.$vo['wsarticle_id'])}" data-action="{:url('@admin/wsphoto/update')}">修改</a></td>
                <td class="text-center"><a class="copy" data-url="{:url('@admin/wsarticle/copy', 'id='.$vo['wsarticle_id'])}">复制</a></td>
                <td class="text-center"><a class="delete" data-url="{:url('@admin/wsarticle/delete','id='.$vo['wsarticle_id'])}">删除</a></td>
            </tr>
            {/volist}
        </tbody>
    </table>
    {empty name="list"}
    <div class="mb20 mt20 text-center">
        {if ($keywords!='')}
            未搜索到 “{$keywords}” 相关的内容 &nbsp; <a href="{:url('@admin/wsphoto', $urlparam)}">查看全部内容</a>
        {else /}
            暂未添加内容
        {/if}
    </div>
    {/empty}
    {notempty name="list"}
    <div class="mb10 ml10">
        <button class="btn btn-danger check-delete" type="button" data-url="{:url('@admin/wsarticle/delete')}">删除内容</button> 
    </div>
    {/notempty}
</div>

<div class="text-center mb20">
    {$list|raw}
</div>


<form method="post" class="form-horizontal" id="form-modal-submit">
    <input type="hidden" name="wsarticle_id" id="wsarticle_id" value="0">
    <input type="hidden" name="wsarticle_siteid" id="wsarticle_siteid" value="{$siteid}">
    <input type="hidden" name="wsarticle_columnid" id="wsarticle_columnid" value="{$columnid}">
    <div class="modal fade" data-backdrop="static" id="modal-create">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">内容管理</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="wsarticle_title" class="col-sm-2 required">名称</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="wsarticle_title" id="wsarticle_title" value="" placeholder="图片名称" required>
                        </div>
                        <div class="col-sm-3">
                            <p class="help-block">名称</p>
                        </div>
                    </div>
                    {if($column['column_cate'])}
                    <div class="form-group">
                        <label class="col-md-2 col-sm-2 required" for="wsarticle_title">分类</label>
                        <div class="col-sm-7">
                            <select class="form-control" name="wsarticle_cateid">
                                {volist name="wscate" id="vo"}
                                <option value="{$vo['wscate_id']}">{:dp_prefix($vo['wscate_path'])}{$vo['wscate_name']}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="col-sm-3 help-block with-errors"></div>
                    </div>
                    {/if}
                    <div class="form-group">
                        <label for="wsarticle_image" class="col-sm-2 required">图片</label>
                        <div class="col-sm-9">
                            <div class="input-group">
                                <input type="text" class="form-control" name="wsarticle_image" placeholder="选择文件: jpg, png, gif" readonly>
                                <span class="input-group-btn">
                                    <button type="button" class="btn text-primary" data-param-upload data-param-type="image" data-input-name="wsarticle_image">上传</button>
                                    <button type="button" class="btn text-success" data-param-preview data-input-name="wsarticle_image">预览</button>
                                    <button type="button" class="btn text-danger" data-param-delete data-input-name="wsarticle_image">删除</button>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="wsarticle_desc" class="col-sm-2">描述</label>
                        <div class="col-sm-8">
                            <textarea name="wsarticle_desc" rows="5" id="wsarticle_desc" class="form-control"></textarea>
                        </div>
                    </div>
                    {volist name="param" id="vo"}
                    <div class="form-group">
                        <label class="col-sm-2 {$vo['param_required'] != '1' ?: 'required'}" for="param_{$vo['param_id']}">{$vo['param_name']}</label>
                        {if($vo['param_type']=='editor')}
                            <div class="col-sm-8 help-block">不支持编辑器</div>
                        {slseif($vo['param_type']=='image')}
                            <div class="col-sm-8 help-block">不支持图片上传</div>
                        {slseif($vo['param_type']=='file')}
                            <div class="col-sm-8 help-block">不支持附件上传</div>
                        {else /}
                            <div class="col-sm-7">{:make_input($vo)}</div>
                            <div class="col-sm-3 help-block"><code>$param_{$vo['param_id']}</code></div>
                        {/if}
                    </div>
                    {/volist}
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </div>
        </div>
    </div>
</form>
{/block}

<!-- JS -->
{block name="js"}
    {load href="/static/lib/jquery/jquery.form.js"}
    {load href="/static/lib/jquery/jquery.autofill.min.js"}
    {load href="/static/lib/validator/validator.min.js"}
    {load href="/static/lib/simpleupload/simpleUpload.min.js"}
{/block}

{block name="jscode"}
<script type="text/javascript">
$(document).ready(function() {
    var settings_image = {
        uploadUrl: "{:url('@admin/upload/image')}",
        accept: "image/*",
        allowedExts: ["jpg", "jpeg", "png", "gif"], // 允许上传后缀
        allowedTypes: ["image/pjpeg", "image/jpeg", "image/png", "image/x-png", "image/gif", "image/x-gif"],
    };

    // 上传文件
    $("[data-param-upload]").click(function(event) {
        var param_type = $(this).data('param-type');
        var input_name = $(this).data('input-name');

        if ($("input[name=" + input_name + "]").val() != '') {
            if (param_type == 'image') {
                return sxj.msg_error('提示：请先删除图片!');
            }
            if (param_type == 'file') {
                return sxj.msg_error('提示：请先删除附件!');
            }
        }
        
        // 配置文件
        var settings = settings_image;

        // 开始上传
        var startFunc = function(file) {sxj.loading();}

        // 上传成功
        var successFunc = function(response) {
            sxj.msg_success('文件上传成功');
            var data = response.data;
            $("input[name=" + input_name + "]").val(data.file_path)
        }

        // 调用上传插件
        sxj.upload(settings, successFunc, startFunc);
    });

    // 预览 下载
    $("[data-param-preview],[data-param-download]").click(function(event) {
        var input_name = $(this).data('input-name');
        var file_path = $("input[name="+input_name+"]").val();
        if(file_path == ''){
            return sxj.msg_error('提示：文件不存在');
        }
        window.open(file_path);
    });

    // 删除文件
    $("[data-param-delete]").click(function(event) {
        var input_name = $(this).data('input-name');
        var file_path = $("input[name='" + input_name + "']").val();
        if(file_path == ''){
            return sxj.msg_error('提示：文件不存在');
        }
        var url = "{:url('@admin/upload/delete')}?file_path=" + file_path;
        sxj.upload_delete(url, input_name);
    });

    // 图片预览
    $('a.lightbox-toggle').lightbox({image: $(this).attr('href')});
});
</script>
{/block}